 

import '@material/web/all.js';
import { infoUtil } from "./util/infoUtil";
import { file} from "ispace.core.main"


let params = new URLSearchParams(window.location.search);
let path = params.get("path");

class Program {

    public static main(){  
        console.log("Hyperlink Edit Page");
        if((path?.length??0) == 0)
        {
            infoUtil.displayErrorInfo("文件地址不可空！");
            return;
        }
 
        // step 1: 获取文件内容
        file.content(path!).subscribe(url => { 
               const input = document.getElementById("dataPath") as any;
               input.value = url;
            }, error => {
                    infoUtil.displayErrorInfo(error);
    }); 
    }

}

Program.main();

export function update(){ 
   const dp = document.getElementById("dataPath") as any;
   if((dp.value?.length??0) == 0)
    {
        infoUtil.displayErrorInfo("超链接不可为空！");
        return;
    } 
   file.write(path!,dp.value!).subscribe(s=>{
    infoUtil.displayInfo("保存成功！");
   },error => {
    infoUtil.displayErrorInfo(error);
});
}

(window as any).update = update; 